namespace GemBox.Spreadsheet
{
    using System;
    using System.ComponentModel;

    public abstract class ExcelColumnRowBase
    {
        private bool collapsed;
        private bool hidden;
        internal int IndexInternal;
        private int outlineLevel;
        private ExcelRowColumnCollectionBase parent;
        private CellStyle style;

        [EditorBrowsable(EditorBrowsableState.Never)]
        protected ExcelColumnRowBase(ExcelRowColumnCollectionBase parent, ExcelColumnRowBase source)
        {
            this.parent = parent;
            this.IndexInternal = source.IndexInternal;
            this.collapsed = source.collapsed;
            this.outlineLevel = source.outlineLevel;
            this.hidden = source.hidden;
            this.Style = source.Style;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        protected ExcelColumnRowBase(ExcelRowColumnCollectionBase parent, int index)
        {
            this.parent = parent;
            this.IndexInternal = index;
        }

        public bool Collapsed
        {
            get
            {
                return this.collapsed;
            }
            set
            {
                this.collapsed = value;
            }
        }

        internal abstract int Extent { get; }

        public bool Hidden
        {
            get
            {
                return this.hidden;
            }
            set
            {
                this.hidden = value;
            }
        }

        public int Index
        {
            get
            {
                return this.IndexInternal;
            }
        }

        public bool IsStyleDefault
        {
            get
            {
                if (this.style != null)
                {
                    return this.style.IsDefault;
                }
                return true;
            }
        }

        public int OutlineLevel
        {
            get
            {
                return this.outlineLevel;
            }
            set
            {
                if ((value < 0) || (value > 7))
                {
                    throw new ArgumentOutOfRangeException("value", value, "OutlineLevel must be in range from 0 to 7.");
                }
                this.outlineLevel = value;
                if (this.outlineLevel > this.parent.MaxOutlineLevel)
                {
                    this.parent.MaxOutlineLevel = this.outlineLevel;
                }
            }
        }

        internal ExcelRowColumnCellCollectionBase Parent
        {
            get
            {
                return this.parent;
            }
        }

        public CellStyle Style
        {
            get
            {
                if (this.style == null)
                {
                    this.style = new CellStyle(this.Parent.Parent.ParentExcelFile.CellStyleCache);
                }
                return this.style;
            }
            set
            {
                this.style = new CellStyle(value, this.parent.Parent.ParentExcelFile.CellStyleCache);
            }
        }
    }
}
